﻿<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>国内出货扫描</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">	
    <link rel="stylesheet" href="../4/lumen/bootstrap.css" media="screen">
    <link rel="stylesheet" href="../_assets/css/custom.min.css">
	<link rel="stylesheet" href="../layui/css/layui.css"/>
	<script src="../_vendor/jquery/dist/jquery.min.js"></script>
    <script src="../_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="../_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../_assets/js/custom.js"></script>
	<script src="../layui/layui.js"></script>
  </head>
  <body >
 
	  	<fieldset class="layui-elem-field site-demo-button">
			<legend><big><b id="information">信息扫入</b></big></legend>
			<div id="DQ" class="layui-fluid layui-form layui-form-pane">
				<div class="layui-col-sm7">
						<label class="layui-form-label">发货单号:</label>
						<div class="layui-input-block">
							<input class="layui-input"  placeholder="FA180917156" id="Fahuo" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm4">
					
				</div>
				<div class="layui-col-sm7">
					<label class="layui-form-label">外箱标签:</label>
					<div class="layui-input-block">
						<input class="layui-input"  placeholder="XN1871202 T2850731C-R8701 50R5 9.0 9.3 135 140 70 168000 100 8918016" id="inbox" type="text"/>
					</div>
				</div>
				<div class="layui-col-sm3">
					<label class="layui-form-label">验证:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="" id="msgin" type="text"/>
					</div>	
				</div>
				<div class="layui-col-sm7">
					<label class="layui-form-label">内箱标签:</label>
					<div class="layui-input-block">
						<input class="layui-input" placeholder="XN1871202 T2850731C-R8701 50R5 9.0 9.3 135 140 70 40000 100 8918018" id="outbox" type="text"/>
					</div>
				</div>
				<div class="layui-col-sm3">
					<label class="layui-form-label">验证:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="" id="msg" type="text"/>
					</div>	
				</div>
				
				<div class="layui-col-sm7">
						<label class="layui-form-label">当前编号:</label>
						<div class="layui-input-block">
							<input class="layui-input" readonly=true placeholder="8918022" id="bianhao" type="text"/>
						</div>
				</div>
				<div class="layui-col-sm3">
					<label class="layui-form-label">当前数量:</label>
					<div class="layui-input-block">
						<input class="layui-input" readonly=true placeholder="40000" id="number" type="text"/>
					</div>	
				</div>
				
				</div>
			</div>
		</fieldset>
		
	<form id="myform">
		<div class="form-group row">
		  <div class="col-sm-4">
			<p class="lead">
			<a class="btn btn-primary btn-lg" href="index.html" role="button">返回</a>
			</p>
		  </div>
		  <div class="col-sm-4">
			<button type="button" id="btnNextbox" class="btn btn-primary">下一箱</button>
		  
		  </div>
		</div>	
		<div class="form-group row" id="my"></div>
		
		 <div class="row">
			<div class="col-md-12">
				<table class="table table-hover" id="dats_table">
					<thead>
						<tr>
							<th id="number1">序号</th>
							<th>工单</th>
							<th>型号</th>
							<th>Bin Code</th>
							<th>电压</th>
							<th>光通量</th>
							<th>显指</th>
							<th>外箱Qty</th>
							<th>电流</th>
							<th>流水号</th>
							<th id="sumqty1">内箱总和</th>
						</tr>
				 	</thead>
				 	<tbody>
						
				 	</tbody>
				</table>
			</div>
		</div> 
	</form>	
	
	<script>
	var inboxsnum=0;
	
	var testlotID=0;//测试lotID是否重复
	var sumqty=0;
	var oks=0;
	var a = new Array();
	var inboxs = new Array();
	var inboxdata={};
	var b = new Array();
	var  disksnumber=0;
	var LMS = new Array();	
	var orders = new Array();	
	var xinghaos = new Array();	
	layui.use(['layer','form','element'], function(){
	
	});
	
	
		$("#Fahuo").keypress(function(e){
			
			var key = e.which;
			if (key == 13) {
				var fahuo= $("#Fahuo").val();
				console.log(fahuo);
				$.ajax({
					type:'POST',
					url: "internal.php",//POST傳一個超長字串到後端
					data:"Order="+fahuo,//通过订单号和铝箔袋二维码获取唯一一条记录
					dataType : "JSON",
					success: function(sss){
						console.log(sss[0]);
						for(var i=0;i<sss.length;i++){
							LMS[i]=sss[i][0];
							orders[i]=sss[i][1];
							xinghaos[i]=sss[i][2];
							//console.log(xinghaos[i].substring(0,xinghaos[i].length-1));
						}
						
						
					}
				});
				$( "#inbox" ).select();//光标选中
			}
		});
	
	
		$("#inbox").keypress(function(e){    //通過訂單號獲取bincode信息
		  var key = e.which;
		  var f='n';
			if (key == 13) {
				var inbox=$("#inbox").val();
				var yanzheng='f';
				f='n';
				for(var i=0;i<inboxs.length;i++){//判断外箱是否重复读取
					if(inbox==inboxs[i]){
						f='t';
						layer.msg('请勿重复扫入');
						$("#msgin").val("请勿重复扫入").css('color','red');
					}
				}
				if(f=='n'){
					inboxs.push(inbox);//整个外箱二维码的数组
					var boxs = inbox.split(' ');//空格切割后的数组
					var data = boxs[0]+boxs[1]+boxs[2]+boxs[3]+boxs[4]
						+boxs[5]+boxs[6]+boxs[7]+boxs[9];
					var LM='LM('+parseFloat(boxs[5])+'-'+parseFloat(boxs[6])+')VF('+
						parseFloat(boxs[3])+'-'+parseFloat(boxs[4])+')CIE('+boxs[2]+
						')RA('+boxs[7]+')IF('+boxs[9]+')';//去掉多余的0//LM(130-135)VF(8.7-9)CIE(50R5)RA(70)IF(100)
					inboxsnum=inboxs.length;//外箱数组长度
					inboxdata[data]=inboxsnum;//去除编号和数量的数组
					console.log(LM+'--'+boxs[0]+'--'+boxs[1]);
					for(var i=0;i<LMS.length;i++){
						if(LM==LMS[i]&&boxs[0]==orders[i]&&(boxs[1]==xinghaos[i] || boxs[1]==xinghaos[i].substring(0,boxs[1].length))){//判断Lm工单和型号是否在U8内存在
							var number = $("<td></td>").append(inboxsnum);
							var order_id = $("<td id='"+'order_id'+inboxsnum+"'></td>").append(boxs[0]);
							var xinghao=$("<td id='"+'xinghao'+inboxsnum+"'></td>").append(boxs[1]);
							var BinCode=$("<td id='"+'BinCode'+inboxsnum+"'></td>").append(boxs[2]);
							var Vr= $("<td id='"+'Vr'+inboxsnum+"'></td>").append(boxs[3]+'-'+boxs[4]);
							var GuangTongL=$("<td id='"+'GuangTongL'+inboxsnum+"'></td>").append(boxs[5]+'-'+boxs[6]);
							var XianZhi=$("<td id='"+'XianZhi'+inboxsnum+"'></td>").append(boxs[7]);
							var inboxqty=$("<td id='"+'inboxqty'+inboxsnum+"'></td>").append(boxs[8]);
							var Ir=$("<td id='"+'Ir'+inboxsnum+"'></td>").append(boxs[9]);
							var BianHao=$("<td id='"+'BianHao'+inboxsnum+"'></td>").append(boxs[10]);
							var outboxqty=$("<td id='"+'outboxqty'+inboxsnum+"'></td>").append(0);
							$("<tr id='"+'shipmenttr'+inboxsnum+"'></tr>")
								.append(number).append(order_id).append(xinghao)
								.append(BinCode).append(Vr).append(GuangTongL).append(XianZhi)
								.append(inboxqty).append(Ir).append(BianHao).append(outboxqty)
								.appendTo("#dats_table tbody ");//将td放入tr内在放入tbody然后将整行置顶
							$("#msgin").val("验证通过").css('color','green');
							yanzheng='t';
							break;
						}
					}
					if(yanzheng=='f'){
						$("#msgin").val("验证失败").css('color','red');
					}
					//var outboxqty=;
				}
				$("#inbox").select();
				console.log(inboxdata[data]+'-'+$("#inboxqty"+inboxsnum).html());
			
			}
			
			
		});
		
		
		
		$("#outbox").keypress(function(e){//手动输入后两位补充码
			var key = e.which;
			var bh='f';
			if (key == 13) {
				var outbox=$("#outbox").val();
				var outboxs = outbox.split(' ');//空格切割后的数组
				$("#outbox").select();
				$("#bianhao").val(outboxs[10]);
				$("#number").val(outboxs[8]);
				var data = outboxs[0]+outboxs[1]+outboxs[2]+outboxs[3]+outboxs[4]
					+outboxs[5]+outboxs[6]+outboxs[7]+outboxs[9];
				console.log(data + '--' + inboxdata[data]);
				if(inboxdata[data]){
				console.log(bh);
					for(var i=0;i<a.length;i++){
						if(outboxs[10]==a[i]){
							layer.msg(outboxs[10]+'-该流水码已存在');
							$("#msg").val(outboxs[10]+'-该流水码已存在').css('color','red');
							bh='t';
						}
					}
					if(bh=='f'){
						
						var outqty=parseInt($("#outboxqty"+inboxdata[data]).html())+parseInt(outboxs[8])
						if(outqty>parseInt($("#inboxqty"+inboxdata[data]).html())){
							layer.msg('改单号已达到出货量请检查是否有误');
							$("#msg").val('改单号已达到出货量请检查是否有误').css('color','red');
						}
						else{
							$("#outboxqty"+inboxdata[data]).html(outqty);
							a.push(outboxs[10]);
							$("#msg").val("验证通过").css('color','green');
						}
						
						if($("#outboxqty"+inboxdata[data]).html()!=''&&parseInt($("#outboxqty"+inboxdata[data]).html())==parseInt($("#inboxqty"+inboxdata[data]).html())){
							$("#shipmenttr"+inboxdata[data]).css('color','green');
							oks++;
						}
						
					}
					
					
					console.log(oks);
					if(oks==inboxs.length){
						$("#dats_table tbody").empty();
						$( "#Fahuo" ).select();
						$("#msg").val("");
						$("#inbox" ).val("");
						$("#msgin").val("");
						$("#outbox").val("");
						inboxdata={};
						inboxs=[];
						a=[];
						oks=0;
						console.log(inboxdata+'-'+inboxs);
					}
					
					
				}
				else{
					$("#msg").val("验证失败").css('color','red');
				}
			
			
			}
		});			
	
		
			
	
	
	
		$("#btnNextbox").click(function(){//点击按钮后将table清空并清空标记符
			$( "#Fahuo" ).select();
			$("#dats_table tbody").empty();
			$("#msg").val("");
			$("#inbox" ).val("");
			$("#msgin").val("");
			$("#outbox").val("");
			oks=0;
			inboxdata={};
			inboxs=[];
			
		});	
	</script>
  </body>
</html>